/**
 * Created by liutongbin on 2018/1/12.
 */
;(function($){
    $(function() {
        var current = 0;
        var timeId;
        var len = $(".mySlides").length;

        function render(num) {

            $(".mySlides").hide();
            $(".mySlides[index=" + num + "]").show();
            $(".dot").removeClass("active");
            $(".dot[index=" + num + "]").addClass("active");
            $(".black").removeClass("new");
            $(".black[index=" + num + "]").addClass("new");
            intervalChange();
        }

        function renderCircle(e) {


        }
        // intervalChange();

        // renderCircle();
        function intervalChange() {
            var len = $('.mySlides').length;

            clearInterval(timeId);
            timeId = setInterval(function () {

                current++;
                // current--;
                if (current >= len) {
                    current = 0;
                    // render(current)
                }

                render(current);
            }, 2000)
            // current++;

            // current = current-1;
            console.log(current)
        }


        render(0);

        $(".dot").on("click", function () {
            var $this = $(this),
                t = $this.attr("index");
            // current = t;
            render(t)
            current = t;

        })
        $(".next").on("click", function () {
            var len = $(".mySlides").length;

            if(current < (len-1)){
                current = current + 1;
                console.log(current);
                render(current);
            }else {
                // render(len-1)
            }



        })

        $(".prev").on("click", function () {

            if(current > 0){
                current = current-1;
                console.log(current);
                render(current);
            }else{
                // render(0)
            }

        })


    })















})(jQuery);